﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration.Install;
using System.Linq;
using System.ServiceProcess;


namespace TPTecnicas.MessageProcessor.Processor
{
    [RunInstaller(true)]
    public partial class MessageProcessorInstaller : Installer
    {
        private readonly ServiceInstaller _serviceInstaller;
        private readonly ServiceProcessInstaller _processInstaller;

        public MessageProcessorInstaller()
        {
            InitializeComponent();
            _processInstaller = new ServiceProcessInstaller();
            _serviceInstaller = new ServiceInstaller();

            // Service will run under system account
            _processInstaller.Account = ServiceAccount.LocalSystem;

            // Service will have Start Type of Manual
            _serviceInstaller.StartType = ServiceStartMode.Automatic;

            Installers.Add(_serviceInstaller);
            Installers.Add(_processInstaller);
        }

        public override void Install(IDictionary stateSaver)
        {
            _serviceInstaller.ServiceName = Context.Parameters["servicename"];
            base.Install(stateSaver);
        }

        public override void Uninstall(IDictionary savedState)
        {
            _serviceInstaller.ServiceName = Context.Parameters["servicename"];
            base.Uninstall(savedState);
        }
    }
}
